#ifndef DATABASEMANAGER_H
#define DATABASEMANAGER_H

#include <QObject>

#include <QSqlDatabase>
#include <QSqlRelationalTableModel> // 多表操作
#include <QSqlQuery>

class DatabaseManager : public QObject
{
    Q_OBJECT
public:
    static DatabaseManager& getInstance()
    {
        static DatabaseManager instance;
        return instance;
    }
    // 连接数据库
    bool connectMysql();
    // 判断是否登录成功
    bool login(QString username, QString password);

    QSqlDatabase& getDatabase() {return db;}
    QSqlRelationalTableModel* getSerialModel(){return serialModel;}
    QSqlRelationalTableModel* getPortModel(){return portModel;}

signals:

public slots:

private:
    explicit DatabaseManager(QObject *parent = nullptr);
    DatabaseManager(const DatabaseManager&) = delete;
    DatabaseManager& operator=(const DatabaseManager&) = delete;


    QSqlRelationalTableModel* serialModel;
    QSqlRelationalTableModel* portModel;


    QSqlDatabase db;
};

#endif // DATABASEMANAGER_H
